package com.gewu.pm.ui.dialog;

import android.content.Context;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import com.hjq.base.BaseDialog;
import com.gewu.pm.R;

/**
 *  等待加载对话框   根据UI来的 旋转动画
 */
public final class Wait2Dialog {

    public static final class Builder
            extends BaseDialog.Builder<Builder> {

        private final ImageView imgRefresh;

        public Builder(Context context) {
            super(context);
            setContentView(R.layout.wait2_dialog);
            setAnimStyle(BaseDialog.ANIM_TOAST);
            setBackgroundDimEnabled(false);
            setCancelable(false);

            imgRefresh = findViewById(R.id.img_refresh);

            Animation rotateAnimation = AnimationUtils.loadAnimation(context, R.anim.rotate_anim);
            LinearInterpolator lin = new LinearInterpolator();
            rotateAnimation.setInterpolator(lin);
            imgRefresh.startAnimation(rotateAnimation);

        }

        @Override
        public void dismiss() {
            super.dismiss();
            if(imgRefresh!=null){
                imgRefresh.clearAnimation();
            }
        }
    }
}